﻿using Microsoft.AspNetCore.SignalR;

namespace Awsc.DataAcquisitionSys.Api.SingalRServices
{
    public class AlarmHub : Hub
    {
        // 后端会持续向前端发送模拟的传感器数据
        public async Task ReceiveAlarmInfo(List<AlarmInfo> data)
        {
            // 向所有连接的客户端发送传感器数据
            await Clients.All.SendAsync("ReceiveAlarmInfo", data);
        }
    }

    public class AlarmInfo
    {
        public AlarmInfo()
        {

        }
        public AlarmInfo(string message, string subMessage)
        {
            Message = message;
            SubMessage = subMessage;
            AlarmTime = DateTime.Now;
        }
        /// <summary>
        /// 报警级别（0-info显示正常色，1-Warning显示为黄色或者橙色，2-Error显示为红色）
        /// </summary>
        public AlarmLevel Level { get; set; } = AlarmLevel.Error;
        /// <summary>
        /// 报警时间
        /// </summary>
        public DateTime AlarmTime { get; set; }


        /// <summary>
        /// 报警信息
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// 子信息
        /// </summary>
        public string SubMessage { get; set; }

        public string ModeName { get;set; }
        public string SensorName { get; set; }
        public string SensorKey { get; set; }

        public override string ToString()
        {
            return $"{Level}|{AlarmTime}|{SensorKey}|{SensorName}|{Message}|{SubMessage}|{ModeName}";
        }



    }
    public enum AlarmLevel
    {

        Information = 0,
        Warning = 1,
        Error = 2

    }

}
